package com.jt.tenant.adapter;

import android.content.Context;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetViolation;

import java.util.List;


/**
 * Created by Administrator on 2016/2/14.
 */
public class IllegalQueryAdapter extends BaseAdapter {

    private Context context;

    private List<GetViolation.Violation> list;

    public IllegalQueryAdapter(Context context, List<GetViolation.Violation> list) {

        this.context = context;

        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = View.inflate(context, R.layout.activity_illegal_query_item, null);

            holder = new ViewHolder();

            JTApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder.tv_illegal_address = (TextView) convertView.findViewById(R.id.tv_illegal_address);

            holder.tv_illegal = (TextView) convertView.findViewById(R.id.tv_illegal);

            holder.tv_illegal_time = (TextView) convertView.findViewById(R.id.tv_illegal_time);

            holder.tv_illegal_fine = (TextView) convertView.findViewById(R.id.tv_illegal_fine);

            holder.tv_illegal_deduct_mark = (TextView) convertView.findViewById(R.id.tv_illegal_deduct_mark);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        GetViolation.Violation mItem = list.get(position);

        holder.tv_illegal_address.setText(mItem.AREA);

        holder.tv_illegal.setText(mItem.ACT);

        holder.tv_illegal_time.setText(mItem.TIME);

        holder.tv_illegal_fine.setText(fine(mItem.MONEY));

        holder.tv_illegal_deduct_mark.setText("扣分：" + mItem.FEN);

        return convertView;
    }

    class ViewHolder {

        TextView tv_illegal_address;

        TextView tv_illegal;

        TextView tv_illegal_time;

        TextView tv_illegal_fine;

        TextView tv_illegal_deduct_mark;

    }

    private SpannableString fine(String str) {

        SpannableString s = new SpannableString("罚款\n¥" + str);

        s.setSpan(new RelativeSizeSpan(1.2f), 0, 2, 0);

        s.setSpan(new RelativeSizeSpan(0.8f), 2, 3, 0);

        s.setSpan(new RelativeSizeSpan(1.6f), s.length() - str.length(), s.length(), 0);


        return s;

    }
}
